import lxy_event from './lxy_page_event.js';

class Lxy_page_event_dialog extends lxy_event {
	constructor(e) {
		super(e);
		this.init(e);
	}

	init(e) {
		console.log('Lxy_page_event', e);
		this.cfg = e;
	}

	callEvent(expParams, rowIndex = -1, vm) {
		console.log('[Debug][DialogEvent]Call: ', this, this._dataSrc, vm);
		const inputParams = this.calcInputParams(rowIndex);
		console.log('inputParams', inputParams);
		if (inputParams === undefined || (!(inputParams instanceof Object) && isNaN(inputParams))) {
			return null;
		}

		if (this.cfg.ifDialog) {
			if (!this.cfg.dialogCfg || !this.cfg.dialogCfg.pageid) {
				console.error('[Error][PageDialog]The dialog config or pageid no define: ', this.cfg);
				return null;
			}
			console.log('ifDialog');
			vm.handleOpenDialog({ pageid: this.cfg.dialogCfg.pageid * 1, title: this.cfg.dialogCfg.title }, inputParams);
		} else {
			console.log('vm:', vm);
			vm.handleCloseDialog(inputParams);
		}

		return { code: '0000' };
	}
}

export default Lxy_page_event_dialog;
